package leetcodecompetition.D346;

import org.junit.jupiter.api.Test;

public class T6441 {
    public int punishmentNumber(int n) {
        int res = 0;
        for (int i = 1; i <= n; i++) {
            if (is(i, Integer.toString(i * i), 0, 0)) {
                System.out.println(i);
                res += i * i;
            }
        }
        return res;
    }

    public boolean is(int a, String s, int start, int h) {
        if (start==s.length()){
            if (a==h)return true;
            return false;
        }
        boolean b = false;
        for (int i = 1; i <= 3 && start + i <= s.length(); i++) {
            int r = Integer.parseInt(s.substring(start, start + i));
            if (is(a, s, start + i, h + r)) b = true;
        }
        return b;
    }
    @Test
    public void test() {
        System.out.println(punishmentNumber(10));
        System.out.println(is(10,"100",0,0));
    }
}
